package com.aaa.web.service.batterymangerservice.batterymangerserviceimpl;

import com.aaa.entity.BreakBattery;
import com.aaa.entity.ChangekBattery;
import com.aaa.entity.RepairBattery;
import com.aaa.util.EmpUtil;
import com.aaa.web.commons.BatteryInfoQuery;
import com.aaa.web.commons.Result;
import com.aaa.web.dao.baterymangerdao.ProblemBatteryDao;
import com.aaa.web.service.batterymangerservice.ProblemBatteryBIZ;
import com.aaa.web.systemconst.ISystemConst;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * com.aaa.web.service.batterymangerservice.batterymangerserviceimpl class
 *
 * @author Kevin Jia
 * @CLASS:ProblemBatteryBIZImpl
 * @Date:2018/12/22 14:47
 */
@Service
public class ProblemBatteryBIZImpl implements ProblemBatteryBIZ {

    @Autowired
    private ProblemBatteryDao problemBatteryDao;

    /**
     * @Description: 
     * @Param:
     * @return: 
     * @Author: Kevin Jia
     * @Date: 2018/12/22
     * @Time: 14:59
     */
    @Override
    public Map getProblemBatterys(BatteryInfoQuery query, BreakBattery breakBattery) {
        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page, size);
        Map map = new HashMap(ISystemConst.MAP_INCAPACITY);
        List<BreakBattery> problemBatterys = problemBatteryDao.getProblemBatterys(breakBattery);
        if (problemBatterys == null){

            map.put("code", 1);
            map.put("msg", "");
            return map;
        }
        map.put("data", problemBatterys);
        map.put("count", problemBatteryDao.getBreakBatteryCount());
        map.put("code", 0);
        map.put("msg", "");
        return map;
    }

    /**
     * @Description: 删除
     * @Param: String
     * @return: Result
     * @Author: Kevin Jia
     * @Date: 2018/12/22
     * @Time: 15:45
     */
    @Override
    public Result delProblemBattery(String id) {
        Result result = new Result();
        problemBatteryDao.delBreakBattery(id);
        result.setCode(ISystemConst.SU_COD);
        result.setMsg("删除成功");
        return result;
    }

    /**
     * @Description: 修改
     * @Param: BreakBattery
     * @return: Map
     * @Author: Kevin Jia
     * @Date: 2018/12/22
     * @Time: 15:45
     */
    @Override
    public Result updateProblemBattery(BreakBattery breakBattery) {
        Result result = new Result();
        problemBatteryDao.updateBreakBattery(breakBattery);
        result.setCode(ISystemConst.SU_COD);
        result.setMsg("修改成功");
        return result;
    }

    /**
     * @Description: 添加
     * @Param: BreakBattery
     * @return: Map
     * @Author: Kevin Jia
     * @Date: 2018/12/22
     * @Time: 15:45
     */
    @Override
    public Result addProblemBattery(BreakBattery breakBattery) {
        Map map = new HashMap(ISystemConst.MAP_INCAPACITY);
        Result result = new Result();
        problemBatteryDao.insertBreakBattery(breakBattery);
        result.setCode(ISystemConst.SU_COD);
        result.setMsg("添加成功");
        return result;
    }

    @Override
    public Map getAddNames() {
        Map map = new HashMap(ISystemConst.MAP_INCAPACITY);
        String schoolId = String.valueOf(EmpUtil.getEmp().getSchoolid());
        map.put("code", 0);
        map.put("msg", "成功");
        map.put("data",problemBatteryDao.getAddNames(schoolId));
        return map;
    }

    /**
     * @Description: 获取更换电瓶记录
     * @Param: query,changeBattery
     * @return: Map
     * @Author: Kevin Jia
     * @Date: 2018/12/24
     * @Time: 13:44
     */
    @Override
    public Map getChangeBatterys(BatteryInfoQuery query, ChangekBattery changeBattery) {
        Map map = new HashMap(ISystemConst.MAP_INCAPACITY);
        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page,size);
        map.put("data",problemBatteryDao.getChangeBatterys(changeBattery));
        map.put("count",problemBatteryDao.getChangeCount());
        map.put("code",ISystemConst.SU_COD);
        return map;
    }

    /**
     * @Description: 添加
     * @Param: changeBattery
     * @return:
     * @Author: Kevin Jia
     * @Date: 2018/12/24
     * @Time: 13:50
     */
    @Override
    public Result addChangeBattery(ChangekBattery changeBattery) {
        Result result = new Result();
        Integer addInt= problemBatteryDao.addChangeBattery(changeBattery);
        if (addInt>0){
            result.setCode(ISystemConst.SU_COD);
            result.setMsg("添加成功");
            return result;
        }
        result.setCode(ISystemConst.DEFEAT_CODE);
        result.setMsg("添加失败");
        return result;
    }
    /**
     * @Description: 修改更换记录
     * @Param: changeBattery
     * @return: Result
     * @Author: Kevin Jia
     * @Date: 2018/12/24
     * @Time: 14:08
     */
    @Override
    public Result updateChangeBattery(ChangekBattery changeBattery) {
        Result result = new Result();
        problemBatteryDao.updateChangeBattery(changeBattery);
        result.setCode(ISystemConst.SU_COD);
        result.setMsg("修改成功");
        return result;
    }

    /**
     * @Description: 删除
     * @Param: id
     * @return: Result
     * @Author: Kevin Jia
     * @Date: 2018/12/24
     * @Time: 13:54
     */
    @Override
    public Result delChangeBattery(String id) {
        Result result = new Result();
        problemBatteryDao.delChangeBattery(id);
        result.setCode(ISystemConst.SU_COD);
        result.setMsg("删除成功");
        return result;
    }

    /**
     * @Description: 获取修理记录
     * @Param: query,repairBattery
     * @return: Map
     * @Author: Kevin Jia
     * @Date: 2018/12/24
     * @Time: 13:59
     */
    @Override
    public Map getRepairBatterys(BatteryInfoQuery query, RepairBattery repairBattery) {
        Map map = new HashMap(ISystemConst.MAP_INCAPACITY);
        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page, size);
        map.put("data",problemBatteryDao.getRepairBatterys(repairBattery));
        map.put("code",0);
        map.put("count",problemBatteryDao.getRepairCount());
        return map;
    }

    /**
     * @Description: 添加
     * @Param: changeBattery
     * @return: Result
     * @Author: Kevin Jia
     * @Date: 2018/12/24
     * @Time: 13:53
     */
    @Override
    public Result addRepairBattery(RepairBattery changeBattery) {
        Result result = new Result();
        problemBatteryDao.addRepairBattery(changeBattery);
        result.setCode(ISystemConst.SU_COD);
        result.setMsg("添加成功");
        return result;
    }

    /**
     * @Description: 修改
     * @Param: repairBattery
     * @return: result
     * @Author: Kevin Jia
     * @Date: 2018/12/24
     * @Time: 14:00
     */
    @Override
    public Result updateRepairBattery(RepairBattery repairBattery) {
        Result result = new Result();
        problemBatteryDao.updateRepairBattery(repairBattery);
        result.setCode(ISystemConst.SU_COD);
        result.setMsg("修改成功");
        return result;
    }

    /**
     * @Description: 删除
     * @Param:id
     * @return: result
     * @Author: Kevin Jia
     * @Date: 2018/12/24
     * @Time: 14:00
     */
    @Override
    public Result delRepairBattery(String id) {
        Result result = new Result();
        problemBatteryDao.delRepairBattery(id);
        result.setCode(ISystemConst.SU_COD);
        result.setMsg("删除成功");
        return result;
    }

    /**
     * @Description: 获取当前门店下的所有员工信息
     * @Param: none
     * @return: Map
     * @Author: Kevin Jia
     * @Date: 2018/12/24
     * @Time: 20:33
     */
    @Override
    public Map getEmployeeName() {
        String schoolId =String.valueOf(EmpUtil.getEmp().getSchoolid());
        List<RepairBattery> repairBatteries = problemBatteryDao.getEmployeeName(schoolId);
        Map map = new HashMap(ISystemConst.MAP_INCAPACITY);
        map.put("data",repairBatteries);
        map.put("code",ISystemConst.SU_COD);
        return map;
    }
}
